<%@ page language="java"  pageEncoding="UTF-8"%>
<script type="text/javascript">
var shuangchuang_datagrid;
$(function ()
{
    shuangchuang_datagrid = $('#shuangchuang_manager_datagrid').datagrid(
        {
            url : '${pageContext.request.contextPath}/shuangchuangAction!do_datagrid.action',
            queryParams :{deptId:'${sessionInfo.deptId}'},
            pagination : true,
            pageSize : 10,
            pageList : [10, 20, 30, 40],
            border : false,
            fit: true,
            fitColumns : true,
            idField : 'cid',
            sortName : 'cstartdate',
            sortOrder : 'desc',
            checkOnSelect : false,
            selectOnCheck : true,
            columns : [[
                    {
                        title : '编号',
                        field : 'cid',
                        width : 150,
                        align : "center",
                        checkbox : true
                    },
                    {
                        title : '单位名称',
                        field : 'deptName',
                        align : "center",
                        width : 150,
                    },
                    {
                        title : '双创项目名称',
                        field : 'cname',
                        align : "center",
                        width : 200
                    },
                    {
                        title : '项目开始时间',
                        field : 'cstartdate',
                        align : "center",
                        width : 120
                    },
                    {
                        title : '项目结束时间',
                        field : 'cenddate',
                        align : "center",
                        width : 120
                    },
                    {
                        title : '项目状态',
                        field : 'cstatus',
                        align : "center",
                        width : 120,
                        formatter : function (value, row, index)
                        {
                        	if (value === 1){
		 						return '<span style="color:green">进行中</span>';
		 					}else if (value === 2){
		 						return '<span style="color:#FF5600">已完成</span>';
		 					}
                        }
                    },
                    {
                        field : 'action',
                        title : '操作',
                        width : 120,
                        align : 'center',
                        formatter : function (value, row, index)
                        {
                            var str = '';
                        	str += sy.fs(
                                '<img onclick="shuangchuangEdit(\'{0}\');" src="{1}" style="cursor: pointer;" title="修改"/>&nbsp;<img onclick="shuangchuangDelete(\'{2}\');" src="{3}"  style="cursor: pointer;" title="删除"/>&nbsp;',
                                row.cid,
                                'js/themes/icons/pencil.png',
                                row.cid,
                                'js/themes/icons/delete.png');
                        	if (row.cstatus ===1){
                        		str += sy.fs('<img onclick="shuangchuangFinish(\'{0}\');" src="{1}" style="cursor: pointer;" title="项目完成"/>&nbsp;',row.cid,'js/themes/icons/ok.png');;
                        	}
                        	return str;
                        }
                    }
                ]],
            toolbar : [
                {
                    text : '增加',
                    iconCls : 'icon-append',
                    handler : function ()
                    {
                        shuangchuangAppend();
                    }
                }, '-',
                {
                    text : '批量删除',
                    iconCls : 'icon-remove',
                    handler : function ()
                    {
                        shuangchuangRemove();
                    }
                }, '-']
        }
        );
    
}
);

function shuangchuangEdit(cid)
{
    if (cid != undefined)
    {
        $('#shuangchuang_manager_datagrid').datagrid('unselectAll');
        $('#shuangchuang_manager_datagrid').datagrid('selectRecord', cid);
    }
    var rows = $('#shuangchuang_manager_datagrid').datagrid('getSelected');
    var p = parent.sy.dialog(
        {
            title : '双创项目编辑',
            iconCls : 'icon-edit',
            href : '${pageContext.request.contextPath}/shuangchuangAction!shuangchuangEdit.action',
            width : 550,
            height : 200,
            buttons : [
                {
                    text : '保存',
                    iconCls : 'icon-save',
                    handler : function ()
                    {
                        var f = p.find('form');
                        f.form('submit',
                        {
                            url : '${pageContext.request.contextPath}/shuangchuangAction!edit.action',
                            success : function (d)
                            {
                                var json = $
                                    .parseJSON(d);
                                if (json.success)
                                {
                                    shuangchuang_datagrid.datagrid('reload');
                                    p.dialog('close');
                                }
                                parent.sy.messagerShow(
                                {
                                    msg : json.msg,
                                    title : '提示'
                                }
                                );
                            }
                        }
                        );
                    }
                }
            ],
            onLoad : function ()
            {
                var f = p.find('form');
                f.form('load',rows);
            }
        }
        );
};
function shuangchuangAppend()
{
    var p = parent.sy.dialog(
        {
            title : '添加双创项目',
            iconCls : 'icon-append',
            href : '${pageContext.request.contextPath}/shuangchuangAction!shuangchuangAdd.action',
            width : 550,
            height : 200,
            buttons : [
                {
                    text : '添加',
                    iconCls : 'icon-ok',
                    handler : function ()
                    {
                        var f = p.find('form');
                        f.form('submit',
                        {
                            url : '${pageContext.request.contextPath}/shuangchuangAction!add.action',
                            success : function (d)
                            {
                                var json = $.parseJSON(d);
                                if (json.success)
                                {
                                    shuangchuang_datagrid.datagrid('reload');
                                    p.dialog('close');
                                }
                                parent.sy.messagerShow(
                                {
                                    msg : json.msg,
                                    title : '提示'
                                }
                                );
                            }
                        }
                        );
                    }
                }
            ]
        }
        );
}
function shuangchuangRemove()
{
    var rows = shuangchuang_datagrid.datagrid('getChecked');
    var ids = [];
    if (rows.length > 0)
    {
        parent.sy.messagerConfirm('请确认', '是否删除当前所选双创项目？', function (r)
        {
            if (r)
            {
                for (var i = 0; i < rows.length; i++)
                {
                    ids.push(rows[i].cid);
                }
                $.ajax(
                {
                    url : '${pageContext.request.contextPath}/shuangchuangAction!delete.action',
                    data :
                    {
                        ids : ids.join(',')
                    },
                    dataType : 'json',
                    success : function (d)
                    {
                        shuangchuang_datagrid.datagrid('load');
                        shuangchuang_datagrid.datagrid('unselectAll');
                        parent.sy.messagerShow(
                        {
                            title : '提示',
                            msg : d.msg
                        }
                        );
                    }
                }
                );
            }
        }
        );
    }
    else
    {
        parent.sy.messagerAlert('提示', '请选择要删除的双创项目！', 'error');
    }
};

function shuangchuangDelete(cid)
{
    $('#shuangchuang_manager_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
    $('#shuangchuang_manager_datagrid').datagrid('checkRow', $('#shuangchuang_manager_datagrid').datagrid('getRowIndex', cid));
    shuangchuangRemove();
};

function shuangchuangFinish(cid) {
	if (cid != undefined)
    {
        $('#shuangchuang_manager_datagrid').datagrid('unselectAll');
        $('#shuangchuang_manager_datagrid').datagrid('selectRecord', cid);
    }
    var rows = $('#shuangchuang_manager_datagrid').datagrid('getSelected');
	parent.sy.messagerConfirm('提示', '确认双创项目【'+rows.cname+'】已完成？', function (r)
	        {
	            if (r)
	            {
					$.ajax(
				            {
				                url : '${pageContext.request.contextPath}/shuangchuangAction!finish.action',
				                data :
				                {
				                	'cid':cid
				                    
				                },
				                dataType : 'json',
				                success : function (d)
				                {
				                	if (d.success){
				                		shuangchuang_datagrid.datagrid('reload');
				                		shuangchuang_datagrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
				                	}
				                	parent.sy.messagerAlert('提示', d.msg, 'info');
				                }
				            });
	            }
	        });
}

function _searchShuangchuang() {
	shuangchuang_datagrid.datagrid('load', sy.serializeObject($('#shuangchuang_search_from')));
};
function cleanSearchShuangchuang() {
	$('#shuangchuang_search_from table input').val('');
	shuangchuang_datagrid.datagrid('load', sy.serializeObject($('#shuangchuang_search_from')));
};
</script>
<div class="easyui-layout" data-options="fit:true" style="overflow: hidden;">
	<div data-options="region:'north',title:'查询条件（支持模糊查询）',iconCls:'icon-search'" style="height: 150px;padding:5px;border-bottom:none;overflow: hidden;">
		<form id="shuangchuang_search_from">
			<input type="hidden" name="deptId" value="${sessionInfo.deptId}" />
			<table style="height: 100%;" class="input_table">
				<tr>
				    <th >项目名称：</th>
				    <td colspan="3"><input type="text" name="cname" style="width:400px"/></td>
				  </tr>
				  <tr>
				    <th width="100px">项目起始日期：</th>
				    <td width="150px"><input class="easyui-my97" type="text" name="cstartdate" data-options="dateFmt:'yyyy-MM-dd'" /></td>
				    <th width="100px">项目结束日期：</th>
				    <td width="150px"><input class="easyui-my97" type="text" name="cenddate" data-options="dateFmt:'yyyy-MM-dd'" /></td>
				  </tr>
				  <tr>
				    <td colspan="2" align="center"><a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="_searchShuangchuang();">开始查询</a></td>
				    <td colspan="2" align="center"><a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onClick="cleanSearchShuangchuang();">清空条件</a></td>
				  </tr>
			</table>
		</form>
	</div>
	<div data-options="region:'center',title:'双创项目列表',border:true,iconCls:'icon-menu'" style="overflow: hidden;">
		<table id="shuangchuang_manager_datagrid"></table>
	</div>
</div>
